package com.dome.network;

import java.io.IOException;
import java.net.*;

//网络编程UDP接收端
public class ReceivingEnd {
    public static void main(String[] args) throws IOException {
        //创建接收端DatagramSocket对象,将窗口作为参数传递给对象,窗口数必须跟发送端一样
        //在创建一个接收数据的箱子
        //调用DatagramSocket方法接收数据,将数据装到箱子中
        //解析数据信息,打印出来
        //释放资源
        //DatagramSocket ds=new DatagramSocket(7777);
        //创建组播对象
        MulticastSocket ms=new MulticastSocket(7777);
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));
        while (true) {
            byte[] bytes=new byte[1024];
            DatagramPacket dp=new DatagramPacket(bytes,bytes.length);
            ms.receive(dp);
            int length = dp.getLength();
            System.out.println(new String(bytes,0,length));
            ms.close();
        }
    }
}
